<?php
	include "layout.php";
	head();
	if (!isset($_SESSION["id"])) {
		header("Location: index.php");
	}
	if (!isset($_SESSION["oid"])) {
		header("Location: base.php");
	}
?>
<h4 style="text-align: center;">Checkout</h4>
<?php
	if (isset($_POST["submit"])) {
		$oid = $_SESSION["oid"];
		extract($_POST);
		if ($submit == "Yes") {
			$date = date("Y-m-d");
			mysql_query("INSERT INTO orderconfig VALUES ({$oid}, {$_SESSION["id"]}, '{$date}')");
			mysql_query("DELETE FROM orderacc WHERE OrderAcc_ID = {$oid}");
?>
<p style="text-align: center">Your order (ID #<?php echo $oid ?>) has been checked out.<br /> <a href="main.php">Return to main page</a></p>
<?php
			unset($_SESSION["oid"]);
			unset($oid);
		}
		else {
			header("Location: cust.php");
		}
	}
	else {
		$oid = $_SESSION["oid"];
		$queryb = mysql_query("SELECT * FROM oa_items,items WHERE oa_items.OAI_OrderAcc_ID='{$oid}' AND items.Items_ID = oa_items.OAI_Items_ID AND items.Item_Cat = 'B'");
		$queryc = mysql_query("SELECT * FROM oa_items,items WHERE oa_items.OAI_OrderAcc_ID='{$oid}' AND items.Items_ID = oa_items.OAI_Items_ID AND items.Item_Cat = 'C'");
		$queryg = mysql_query("SELECT * FROM oa_items,items WHERE oa_items.OAI_OrderAcc_ID='{$oid}' AND items.Items_ID = oa_items.OAI_Items_ID AND items.Item_Cat = 'G'");
		$queryh = mysql_query("SELECT * FROM oa_items,items WHERE oa_items.OAI_OrderAcc_ID='{$oid}' AND items.Items_ID = oa_items.OAI_Items_ID AND items.Item_Cat = 'H'");
		$query = mysql_query("SELECT * FROM oa_items WHERE OAI_OrderAcc_ID = {$oid}");
		$count = mysql_num_rows($query);
		if ($count != 0) {
?>
<h5>Baked Goods</h5>
<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<th style="width: 300px">Item Name</th>
		<th style="width: 300px">Item Category</th>
	</tr>
<?php
		while ($baked = mysql_fetch_array($queryb)) {
			extract($baked);
			echo <<<Baked
	<tr>
		<td>{$Items_Description}</td>
		<td>Baked Goods</td>
	</tr>
Baked;
		}
?>
</table>
<br />
<h5>Chips</h5>
<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<th style="width: 300px">Item Name</th>
		<th style="width: 300px">Item Category</th>
	</tr>
<?php
		while ($chips = mysql_fetch_array($queryc)) {
			extract($chips);
			echo <<<Chips
	<tr>
		<td>{$Items_Description}</td>
		<td>Chips</td>
	</tr>
Chips;
		}
?>
</table>
<br />
<h5>Gum</h5>
<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<th style="width: 300px">Item Name</th>
		<th style="width: 300px">Item Category</th>
	</tr>
<?php
		while ($gum = mysql_fetch_array($queryg)) {
			extract($gum);
			echo <<<Gum
	<tr>
		<td>{$Items_Description}</td>
		<td>Gum</td>
	</tr>
Gum;
		}
?>
</table>
<br />
<h5>Healthy Alternatives</h5>
<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<th style="width: 300px">Item Name</th>
		<th style="width: 300px">Item Category</th>
	</tr>
<?php
		while ($healthy = mysql_fetch_array($queryh)) {
			extract($healthy);
			echo <<<Healthy
	<tr>
		<td>{$Items_Description}</td>
		<td>Healthy Alternative</td>
	</tr>
Healthy;
		}
?>
</table>
<form method="post" action="checkout.php" style="text-align: center">
	<div class="form_settings">
		<p style="text-align: center;">Are you sure you want to check out?</p>
		<input type="hidden" name="baseline" value="<?php echo $baseline; ?>" />
		<input type="submit" class="submit" name="submit" style="margin-left: 0px;" value="Yes" />
		<input type="submit" class="submit" name="submit" style="margin-left: 33px;" value="No" />
	</div>
</form>
<?php		
		}
		else {
			header("Location: base.php");
		}
	}
?>
<?php
	foot();
?>